<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a="http://richfaces.org/a4j"
	template="/layout/template-base.xhtml" contentType="text/html"
	markupType="xhtml">

	<ui:define name="content">
		
		<ui:include src="/user.xhtml" />
		
		<h:form>
			<s:decorate template="/layout/content.xhtml">
				<h:outputText value="#{messages['timetable.table.title']}"
					styleClass="title color-green" />
				<rich:panel styleClass="panel border-color-green">
					<rich:dataTable columnClasses="data-table-cell" id="timetableTable"
						value="#{horarioAction.horario}" styleClass="data-table"
						var="item" rows="50">
						<rich:column styleClass="align-right">
							<f:facet name="header"><h:outputText value="#{messages['timetable.table.time']}" /></f:facet>
							<h:outputText value="#{item['hora'].horaEntrada}" />:<h:outputText value="#{item['hora'].minutoEntrada}" rendered="#{item['hora'].minutoEntrada gt 9}" /><h:outputText value="0#{item['hora'].minutoEntrada}" rendered="#{item['hora'].minutoEntrada lt 10}" />
							- 
							<h:outputText value=" #{item['hora'].horaSalida}" />:<h:outputText value="#{item['hora'].minutoSalida}" rendered="#{item['hora'].minutoSalida gt 9}" /><h:outputText value="0#{item['hora'].minutoSalida}" rendered="#{item['hora'].minutoSalida lt 10}" />
						</rich:column>
						<rich:column styleClass="align-center">
							<f:facet name="header"><h:outputText value="#{messages['timetable.table.monday']}" /></f:facet>
							<a:commandLink action="#{horarioAction.editarCasilla()}" styleClass="edit-time" reRender="timetablePanels" rendered="#{item['lunes'] != null and (usuario.perfil.administrador or usuario.perfil.horasModificar)}">
								<h:outputText value="#{item['lunes'].grupo.nombre}" />
								<f:setPropertyActionListener value="#{item['lunes']}" target="#{horarioAction.casilla}" />
							</a:commandLink>
							<a:commandLink reRender="timetablePanels" action="#{horarioAction.asignarCasilla(1)}" rendered="#{item['lunes'] == null and (usuario.perfil.administrador or usuario.perfil.horasCrear)}">
								<h:graphicImage value="/img/icons/16/insert.png" alt="#{messages['timetable.table.actions.add']}" title="#{messages['timetable.table.actions.add']}" />
								<f:setPropertyActionListener value="#{item['hora']}" target="#{horarioAction.hora}" />
							</a:commandLink>
						</rich:column>
						<rich:column styleClass="align-center">
							<f:facet name="header"><h:outputText value="#{messages['timetable.table.tuesday']}" /></f:facet>
							<a:commandLink action="#{horarioAction.editarCasilla()}" styleClass="edit-time" reRender="timetablePanels" rendered="#{item['martes'] != null and (usuario.perfil.administrador or usuario.perfil.horasModificar)}">
								<h:outputText value="#{item['martes'].grupo.nombre}" />
								<f:setPropertyActionListener value="#{item['martes']}" target="#{horarioAction.casilla}" />
							</a:commandLink>
							<a:commandLink reRender="timetablePanels" action="#{horarioAction.asignarCasilla(2)}" rendered="#{item['martes'] == null and (usuario.perfil.administrador or usuario.perfil.horasCrear)}">
								<h:graphicImage value="/img/icons/16/insert.png" alt="#{messages['timetable.table.actions.add']}" title="#{messages['timetable.table.actions.add']}" />
								<f:setPropertyActionListener value="#{item['hora']}" target="#{horarioAction.hora}" />
							</a:commandLink>
						</rich:column>
						<rich:column styleClass="align-center">
							<f:facet name="header"><h:outputText value="#{messages['timetable.table.wednesday']}" /></f:facet>
							<a:commandLink action="#{horarioAction.editarCasilla()}" styleClass="edit-time" reRender="timetablePanels" rendered="#{item['miercoles'] != null and (usuario.perfil.administrador or usuario.perfil.horasModificar)}">
								<h:outputText value="#{item['miercoles'].grupo.nombre}" />
								<f:setPropertyActionListener value="#{item['miercoles']}" target="#{horarioAction.casilla}" />
							</a:commandLink>
							<a:commandLink reRender="timetablePanels" action="#{horarioAction.asignarCasilla(3)}" rendered="#{item['miercoles'] == null and (usuario.perfil.administrador or usuario.perfil.horasCrear)}">
								<h:graphicImage value="/img/icons/16/insert.png" alt="#{messages['timetable.table.actions.add']}" title="#{messages['timetable.table.actions.add']}" />
								<f:setPropertyActionListener value="#{item['hora']}" target="#{horarioAction.hora}" />
							</a:commandLink>
						</rich:column>
						<rich:column styleClass="align-center">
							<f:facet name="header"><h:outputText value="#{messages['timetable.table.thursday']}" /></f:facet>
							<a:commandLink action="#{horarioAction.editarCasilla()}" styleClass="edit-time" reRender="timetablePanels" rendered="#{item['jueves'] != null and (usuario.perfil.administrador or usuario.perfil.horasModificar)}">
								<h:outputText value="#{item['jueves'].grupo.nombre}" />
								<f:setPropertyActionListener value="#{item['jueves']}" target="#{horarioAction.casilla}" />
							</a:commandLink>
							<a:commandLink reRender="timetablePanels" action="#{horarioAction.asignarCasilla(4)}" rendered="#{item['jueves'] == null and (usuario.perfil.administrador or usuario.perfil.horasCrear)}">
								<h:graphicImage value="/img/icons/16/insert.png" alt="#{messages['timetable.table.actions.add']}" title="#{messages['timetable.table.actions.add']}" />
								<f:setPropertyActionListener value="#{item['hora']}" target="#{horarioAction.hora}" />
							</a:commandLink>
						</rich:column>
						<rich:column styleClass="align-center">
							<f:facet name="header"><h:outputText value="#{messages['timetable.table.friday']}" /></f:facet>
							<a:commandLink action="#{horarioAction.editarCasilla()}" styleClass="edit-time" reRender="timetablePanels" rendered="#{item['viernes'] != null and (usuario.perfil.administrador or usuario.perfil.horasModificar)}">
								<h:outputText value="#{item['viernes'].grupo.nombre}" />
								<f:setPropertyActionListener value="#{item['viernes']}" target="#{horarioAction.casilla}" />
							</a:commandLink>
							<a:commandLink reRender="timetablePanels" action="#{horarioAction.asignarCasilla(5)}" rendered="#{item['viernes'] == null and (usuario.perfil.administrador or usuario.perfil.horasCrear)}">
								<h:graphicImage value="/img/icons/16/insert.png" alt="#{messages['timetable.table.actions.add']}" title="#{messages['timetable.table.actions.add']}" />
								<f:setPropertyActionListener value="#{item['hora']}" target="#{horarioAction.hora}" />
							</a:commandLink>
						</rich:column>
						<rich:column styleClass="align-center">
							<f:facet name="header"><h:outputText value="#{messages['timetable.table.saturday']}" /></f:facet>
							<a:commandLink action="#{horarioAction.editarCasilla()}" styleClass="edit-time" reRender="timetablePanels" rendered="#{item['sabado'] != null and (usuario.perfil.administrador or usuario.perfil.horasModificar)}">
								<h:outputText value="#{item['sabado'].grupo.nombre}" />
								<f:setPropertyActionListener value="#{item['sabado']}" target="#{horarioAction.casilla}" />
							</a:commandLink>
							<a:commandLink reRender="timetablePanels" action="#{horarioAction.asignarCasilla(6)}" rendered="#{item['sabado'] == null and (usuario.perfil.administrador or usuario.perfil.horasCrear)}">
								<h:graphicImage value="/img/icons/16/insert.png" alt="#{messages['timetable.table.actions.add']}" title="#{messages['timetable.table.actions.add']}" />
								<f:setPropertyActionListener value="#{item['hora']}" target="#{horarioAction.hora}" />
							</a:commandLink>
						</rich:column>
						<rich:column styleClass="align-center">
							<f:facet name="header"><h:outputText value="#{messages['timetable.table.sunday']}" /></f:facet>
							<a:commandLink action="#{horarioAction.editarCasilla()}" styleClass="edit-time" reRender="timetablePanels" rendered="#{item['domingo'] != null and (usuario.perfil.administrador or usuario.perfil.horasModificar)}">
								<h:outputText value="#{item['domingo'].grupo.nombre}" />
								<f:setPropertyActionListener value="#{item['domingo']}" target="#{horarioAction.casilla}" />
							</a:commandLink>
							<a:commandLink reRender="timetablePanels" action="#{horarioAction.asignarCasilla(7)}" rendered="#{item['domingo'] == null and (usuario.perfil.administrador or usuario.perfil.horasCrear)}">
								<h:graphicImage value="/img/icons/16/insert.png" alt="#{messages['timetable.table.actions.add']}" title="#{messages['timetable.table.actions.add']}" />
								<f:setPropertyActionListener value="#{item['hora']}" target="#{horarioAction.hora}" />
							</a:commandLink>
						</rich:column>
						<rich:column>
							<f:facet name="header"><h:outputText value="#{messages['timetable.table.actions']}" /></f:facet>
							<a:commandLink action="#{horarioAction.editarHora()}" reRender="base" rendered="#{(usuario.perfil.administrador or usuario.perfil.horasModificar) and item['hora'].baja == null}">
								<h:graphicImage value="/img/icons/16/edit.png" alt="#{messages['timetable.table.actions.edit']}" title="#{messages['timetable.table.actions.edit']}" />
								<f:setPropertyActionListener target="#{horarioAction.hora}" value="#{item['hora']}" />
							</a:commandLink>
							<a:commandLink action="#{horarioAction.eliminarHora()}" reRender="base" rendered="#{(usuario.perfil.administrador or usuario.perfil.horasEliminar) and item['hora'].baja == null}">
								<h:graphicImage value="/img/icons/16/delete.png" alt="#{messages['timetable.table.actions.delete']}" title="#{messages['timetable.table.actions.delete']}" />
								<f:setPropertyActionListener target="#{horarioAction.hora}" value="#{item['hora']}" />
							</a:commandLink>
						</rich:column>
					</rich:dataTable>
				</rich:panel>
	
				<div class="clear-it"></div>
			</s:decorate>
			
			<s:decorate template="/layout/buttonbar.xhtml">
				<a:commandButton value="#{messages['timetable.actions.new']}" actionListener="#{horarioAction.nuevaHora()}"
					styleClass="btn btn-green" rendered="#{usuario.perfil.administrador or usuario.perfil.horasCrear}" reRender="timetablePanels" />
				<h:commandButton value="#{messages['timetable.actions.list']}" styleClass="btn btn-pink tiny-font" 
					action="#{horarioReport.horario()}">
					<f:setPropertyActionListener target="#{horarioReport.horario}" value="#{horarioAction.horario}" />
				</h:commandButton>
				<h:commandButton value="#{messages['timetable.actions.back']}"
					action="/menu.htm" styleClass="btn btn-blue" />
			</s:decorate>
		</h:form>
		
		<s:div id="timetablePanels">
			<rich:modalPanel id="selectBandPanel" showWhenRendered="true" width="500" height="200" rendered="#{horarioAction.editCasilla}">
				<f:facet name="header">
                    <h:outputText value="#{messages['timetable.addtable.title']}" style="padding-right: 15px;" />
                </f:facet>
                <f:facet name="controls">
                    <h:panelGroup>
						<h:form>
	                        <h:graphicImage value="/img/icons/16/cross.png" styleClass="hide-link" id="closeSelectBandPanel">
	                        	<a:support action="#{horarioAction.hideSelectBandPanel()}" event="onclick" />
	                        </h:graphicImage>
	                        <rich:componentControl for="selectBandPanel" attachTo="closeSelectBandPanel" operation="hide" event="onclick" />
						</h:form>
                    </h:panelGroup>
                </f:facet>
				<h:form>
                	<s:div styleClass="clear-it" />
                	<h:outputText value="#{messages['timetable.addtable.title']}"
						styleClass="title color-blue" />
					<h:panelGrid columns="2" styleClass="modal-panel border-color-blue">
						<h:outputText value="#{messages['timetable.addtable.time']}" styleClass="color-blue" />
						<h:outputText value="#{horarioAction.rango}" />
						
						<h:outputText value="#{messages['timetable.addtable.band']}" styleClass="color-blue" />
						<h:selectOneMenu value="#{horarioAction.grupo}">
							<f:selectItem itemValue="" />
							<s:selectItems value="#{horarioAction.grupos}" var="grupo" label="#{grupo.nombre}" />
							<s:convertEntity />
						</h:selectOneMenu>
					</h:panelGrid>
                	<s:div styleClass="center top-margin">
						<a:commandButton value="#{messages['timetable.addtable.action.add']}" actionListener="#{horarioAction.guardarCasilla()}" reRender="base"
							styleClass="btn btn-blue" rendered="#{usuario.perfil.administrador or usuario.perfil.horasCrear}" />
					</s:div>
				</h:form>
			</rich:modalPanel>
			
			<rich:modalPanel id="hourPanel" showWhenRendered="true" width="500" height="200" rendered="#{horarioAction.editHora}">
				<f:facet name="header">
                    <h:outputText value="#{messages['timetable.addhour.title']}" style="padding-right: 15px;" />
                </f:facet>
                <f:facet name="controls">
                    <h:panelGroup>
						<h:form>
	                        <h:graphicImage value="/img/icons/16/cross.png" styleClass="hide-link" id="closeHourPanel">
	                        	<a:support action="#{horarioAction.hideHourPanel()}" event="onclick" />
	                        </h:graphicImage>
	                        <rich:componentControl for="hourPanel" attachTo="closeHourPanel" operation="hide" event="onclick" />
						</h:form>
                    </h:panelGroup>
                </f:facet>
				<h:form>
                	<s:div styleClass="clear-it" />
                	<h:outputText value="#{messages['timetable.addhour.title']}"
						styleClass="title color-blue" />
					<h:panelGrid columns="2" styleClass="modal-panel border-color-blue">
						<h:outputText value="#{messages['timetable.addhour.start.time']}" styleClass="color-blue" />
						<h:panelGrid columns="3">
							<h:selectOneMenu value="#{horarioAction.hora.horaEntrada}">
								<f:selectItems value="#{horarioAction.horas}" />
							</h:selectOneMenu>
							<h:outputText value=":" />
							<h:selectOneMenu value="#{horarioAction.hora.minutoEntrada}">
								<f:selectItems value="#{horarioAction.minutos}" />
							</h:selectOneMenu>
						</h:panelGrid>
						
						<h:outputText value="#{messages['timetable.addhour.finish.time']}" styleClass="color-blue" />
						<h:panelGrid columns="3">
							<h:selectOneMenu value="#{horarioAction.hora.horaSalida}">
								<f:selectItems value="#{horarioAction.horas}" />
							</h:selectOneMenu>
							<h:outputText value=":" />
							<h:selectOneMenu value="#{horarioAction.hora.minutoSalida}">
								<f:selectItems value="#{horarioAction.minutos}" />
							</h:selectOneMenu>
						</h:panelGrid>
						
					</h:panelGrid>
                	<s:div styleClass="center top-margin">
						<a:commandButton value="#{messages['timetable.addhour.action.save']}" actionListener="#{horarioAction.guardarHora()}" reRender="base"
							styleClass="btn btn-blue" rendered="#{(usuario.perfil.administrador or usuario.perfil.horasCrear) and horarioAction.hora.id == null}" />
						<a:commandButton value="#{messages['timetable.addhour.action.save.changes']}" actionListener="#{horarioAction.guardarHora()}" reRender="base"
							styleClass="btn btn-blue" rendered="#{(usuario.perfil.administrador or usuario.perfil.horasCrear) and horarioAction.hora.id != null}" />
					</s:div>
				</h:form>
			</rich:modalPanel>
		</s:div>
		
	</ui:define>
	
</ui:composition>